package org.senzacontrollo.designPatterns.bridge;

import java.util.Collection;

public class SparseMatrix extends Matrix{

	public SparseMatrix(int rows, int cols, Collection<MatrixCell> data) {
		super(rows, cols, data);
	}

	@Override
	protected void put(int row, int col, int value) {
		MatrixCell cell = getPosition(row, col);
		
		if(cell != null){
			if(value == 0 )
				deletePosition(cell);
			else
				cell.setValue(value);
		}
		else{
			if(value != 0){
				MatrixCell cellToSet = createPosition(row, col);
				cellToSet.setValue(value);
			}
		}
		
	}

	@Override
	protected MatrixCell get(int row, int col) {
		return getPosition(row, col);
	}

}
